//
//  MMNetworkCache.h
//  MMNetworkCache
//
//  Created by issuser on 16/4/26.
//  Copyright © 2016年 zhangli. All rights reserved.
//

#import <UIKit/UIKit.h>

//! Project version number for MMNetworkCache.
FOUNDATION_EXPORT double FFNetworkCacheVersionNumber;

//! Project version string for MMNetworkCache.
FOUNDATION_EXPORT const unsigned char FFNetworkCacheVersionString[];


#import <Foundation/Foundation.h>


/**
 *  离线缓存SDK主操作类
 */
@interface FFNetworkCache : NSObject


/**
 *  创建一个单例实例
 *
 *  @return MMNetworkCache实例对象
 */
+ (FFNetworkCache *)sharedNetworkCache;


/**
 *  配置需要缓存的请求地址，及缓存最大条数
 *
 *  @param cacheConfigBlock     回调需返回缓存的url与时间的键值对
 *  如: 获取产品的请求需要缓存15分钟 @{URL_PRODUCT_GET: @(15 * 60 * 1000)}
 *  @param cacheMaxNumberBlock  回调需返回最大缓存条数，默认最大缓存条数是1000条
 */
- (void)setCacheConfig:(NSDictionary * (^)())cacheConfigBlock cacheMaxNumber:(long (^)())cacheMaxNumberBlock;

/**
 *  获取响应
 *
 *  @param url 请求的url
 *  @param req 请求的body
 *
 *  @return 请求响应
 */
- (NSString *)getRespWithURL:(NSString *)url requestBody:(NSString *)req;



/**
 *  缓存新的请求,如已经缓存则会更新
 *
 *  @param url      请求的url
 *  @param req      请求的body
 *  @param reqTime  请求的发起时间为毫秒数 如：[[NSDate date] timeIntervalSince1970]*1000
 *  @param resp     响应
 *  @param respTime 响应的时间,单位：毫秒数
 */
- (void)putCacheWithURL:(NSString *)url
            requestBody:(NSString *)req
            requestTime:(long long)reqTime
               response:(NSString *)resp
           responseTime:(long long)respTime;


- (BOOL)deleteCacheWithURL:(NSString *)url requestBody:(NSString *)req;


- (BOOL)deleteAllCache;

@end
